import { LoginParams, userLogin } from "@/api/login";
import { useLocalStorage } from "@vueuse/core";

export default defineStore("user", {
  state: () => {
    return {
      username: "",
      role: "",
      accessToken: "",
      refreshToken: "",
    };
  },
  actions: {
    async loginAction(loginParams: LoginParams) {
      const { data: userInfo } = await userLogin(loginParams);
      useLocalStorage("userInfo", userInfo);
      useLocalStorage("token", userInfo.accessToken);
      useLocalStorage("refreshToken", userInfo.refreshToken);
      return userInfo;
    },
  },
});
